home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / dld-3_23.lha / dld-3.2.3 / define.c < prev    next >
C/C++ Source or Header  |  1991-05-30  |  2KB  |  70 lines

  1. /* define.c -- explicitly define a named symbol. */
  2.  
  3. /* This file is part of DLD, a dynamic link/unlink editor for C.
  4.    
  5.    Copyright (C) 1990 by W. Wilson Ho.
  6.  
  7.    The author can be reached electronically by how@cs.ucdavis.edu or
  8.    through physical mail at:
  9.  
  10.    W. Wilson Ho
  11.    Division of Computer Science
  12.    University of California at Davis
  13.    Davis, CA 95616
  14.  */
  15.  
  16. /* This program is free software; you can redistribute it and/or modify it
  17.    under the terms of the GNU General Public License as published by the
  18.    Free Software Foundation; either version 1, or (at your option) any
  19.    later version. */
  20.  
  21. #include "defs.h"
  22.  
  23. /*
  24.  *  explicitly define the value for symbol NAME.
  25.  *
  26.  *  SIZE is the number of bytes required.
  27.  */
  28. dld_define_sym (name, size)
  29. char *name;
  30. unsigned int size;
  31. {
  32.     register char *p = 0;
  33.     struct nlist dummy_nlist;        /* simulate a nlist entry so that
  34.                        _dld_entery_global_ref can be used. */
  35.     register int old_undefined_sym_count;
  36.     
  37.     if (name == 0 || size == 0)
  38.     return 0;
  39.  
  40.     if (setjmp (_dld_env)) {
  41.     if (p) free (p);
  42.     return dld_errno;
  43.     }
  44.     
  45.     if (_dld_dummy_entry == 0)
  46.     _dld_create_dummy_entry ();
  47.  
  48.     bzero (&dummy_nlist, sizeof (struct nlist));
  49.  
  50.     p = (char *) _dld_malloc (strlen(name) +2);
  51.     *p = '_';
  52.     strcpy (p+1, name);
  53.  
  54.     dummy_nlist.n_un.n_name = p;
  55.     dummy_nlist.n_type = N_UNDF | N_EXT;
  56.     dummy_nlist.n_value = size;
  57.  
  58.     old_undefined_sym_count = dld_undefined_sym_count;
  59.     _dld_enter_global_ref (_dld_dummy_entry, &dummy_nlist, p);
  60.  
  61.     free (p);
  62.  
  63.     if (old_undefined_sym_count != dld_undefined_sym_count) {
  64.     _dld_patch_all_files (_dld_latest_entry);
  65.     _dld_exec_flags_valid = 0;
  66.     }
  67.     
  68.     return 0;
  69. } /* dld_define_sym */
  70.